<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link href="./lib/layui-v2.5.5/css/layui.css"  rel="stylesheet"/>
		<script src="./lib/layui-v2.5.5/layui.js"></script>
	</head>
	<body>	
		<div class="layui-container">
			<div class="layui-row">
				<h1 style="text-align: center;margin: 3%;">召回单填写</h1>
			</div>
			<div id="register" class="layui-row">
				<div class="layui-col-md8 layui-col-md-offset2">
				<form class="layui-form">
				  <div class="layui-form-item">
					<label class="layui-form-label">产品编号</label>
					<div class="layui-input-inline">
					  <input type="text" name="pid" id="pid" lay-verify="required" autocomplete="off" class="layui-input" readonly="true">
					</div>
				  </div>
				 <div class="layui-form-item">
					 <label class="layui-form-label">卖家id</label>
					 <div class="layui-input-inline">
					   <input type="text" name="uid" id="uid"  lay-verify="required"  autocomplete="off" class="layui-input" readonly="true">
					 </div>
				 </div>
				 <div class="layui-form-item">
					 <label class="layui-form-label">原因</label>
					 <div class="layui-input-inline">
					   <textarea id="reason" name="reason" cols="40" rows="4"></textarea>
					 </div>
				 </div>
				 <div class="layui-form-item">
					 <label class="layui-form-label">联系方式</label>
					 <div class="layui-input-inline">
					   <input type="text" name="phone" id="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
					 </div>
				 </div>
				 <div class="layui-form-item">
					<label class="layui-form-label">备注</label>
					<div class="layui-input-inline">
					  <textarea id="premark" name="premark" cols="40" rows="4"></textarea>
					</div>
				  </div>				  
				  <div class="layui-form-item">
					<div class="layui-input-block">
					  <button class="layui-btn" lay-submit lay-filter="registersubmit">申请</button>
					  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				  </div>
					</form>				
				</div>							
			</div>			
		</div>			
		<script>
			layui.use(['form','jquery','layer'], function(){
			  var form = layui.form,
				  $ = layui.jquery,
				  layer = layui.layer;
			var pid =  $("#pid", top.document).text();	
			$("#pid").attr("value",pid);
			$.ajax({
				url: "http://localhost:9906/product/getproduct/"+pid,
				type: 'get',
				success:function(response){
					if(response.code==200){	
						$("#uid").attr("value",response.data.uid);
					}else{
						alert("商品已不存在或已删除！");
					}
				},
				error:function(){
					alert("交互错误！");
				}			
			});
			
			
			 //监听提交
			  form.on('submit(registersubmit)', function(){		
				var backmes = {
					bid : 0,
					pid : $("#pid").val(),
					uid : $("#uid").val(),
					reason : $("#reason").val(),
					premark : $("#premark").val(),
					phone : $("#phone").val(),
					status : 0
				};
				console.log(JSON.stringify(backmes));
				$.ajax({
					url:"http://localhost:9906/backmes/add",
					type:'post',
					data:JSON.stringify(backmes),
					dataType:'json',
					contentType: "application/json",
					success:function(data){
						if(data.code == 100){
							layer.msg(data.msg,{icon: 5});//失败的表情
							return;
						}else if(data.code == 200){
							layer.msg("申请成功！请等待联系！", {
								icon: 6,//成功的表情
								time: 2000 //1秒关闭（如果不配置，默认是3秒）
							}, function(){
								var mylay = parent.layer.getFrameIndex(window.name);							 
								parent.layer.close(mylay);
							});
						}
					}						
				});									
				return false;//阻止表单跳转
			  });
		 			 
			});			
		</script>
	</body>
</html>
